﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace THenu.TinyHourseLib.DesignPattern.Creational_Patterns.Abstract_Factory_Pattern
{
    class AbstractFactory : IPatternDemonstrate
    {
        public void StructuralCode()
        {
            // Abstract factory #1
            Factory factory1 = new ConcreteFactory1();
            Client client1 = new Client(factory1);
            client1.Run();

            // Abstract factory #2
            Factory factory2 = new ConcreteFactory2();
            Client client2 = new Client(factory2);
            client2.Run();
 
        }

        public string PatternDescription()
        {
            string strDescription = @"
Definition
Provide an interface for creating families of related or dependent objects without specifying their concrete classes.

Participants

    The classes and objects participating in this pattern are:

AbstractFactory  (ContinentFactory)
·declares an interface for operations that create abstract products
ConcreteFactory   (AfricaFactory, AmericaFactory)
·implements the operations to create concrete product objects
AbstractProduct   (Herbivore, Carnivore)
·declares an interface for a type of product object
Product  (Wildebeest, Lion, Bison, Wolf)
·defines a product object to be created by the corresponding concrete factory
·implements the AbstractProduct interface
Client  (AnimalWorld)
·uses interfaces declared by AbstractFactory and AbstractProduct classes";
            return strDescription;
        }

        public void RealWorldExample()
        {
            // Create and run the African animal world
            ContinentFactory africa = new AfricaFactory();
            AnimalWorld world = new AnimalWorld(africa);
            world.RunFoodChain();

            // Create and run the American animal world
            ContinentFactory america = new AmericaFactory();
            world = new AnimalWorld(america);
            world.RunFoodChain();
        }
    }
}
